package com.example.app;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.io.IOException;
import java.util.List;

/**
 * Created by Christian on 13/02/14.
 */
public class NewsListAdapter extends ArrayAdapter<Noticia>{

    private List<Noticia> items;
    private int layoutId;
    private Context context;

    public NewsListAdapter(Context context, int layoutId, List<Noticia> items){
        super(context, layoutId, items);
        this.context = context;
        this.layoutId = layoutId;
        this.items = items;
    }

    public View getView(int position, View convertView, ViewGroup parent){
        View row = convertView;

        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        row = inflater.inflate(layoutId, parent, false);

        Noticia noticia = items.get(position);
        TextView titulo  = (TextView)row.findViewById(R.id.new_title);
        TextView lead = (TextView)row.findViewById(R.id.new_lead);
        ImageView icone = (ImageView)row.findViewById(R.id.game_icon);

        titulo.setText(noticia.getTitulo());
        lead.setText(noticia.getLead());
        icone.setImageResource(noticia.getIcone());

        return row;
    }
}
